load_func <- function(
    fun_name, 
    repo = getOption("my.pkg.repo", "https://gitee.com/simon7073/rfunc-kit/raw/main/"),
    file = paste0(trimws(gsub("\\.R\\s*$", "", fun_name)), ".R"),
    envir = .GlobalEnv,
    reload = FALSE
) {
  ## 0. 已存在则直接返回
  if (exists(fun_name, mode = "function", envir = envir, inherits = FALSE) && !reload) {
    # message("‘", fun_name, "’ 已存在，跳过加载。")
    return(invisible(TRUE))
  }
  
  ## 1. 标准化 repo 地址
  repo <- sub("/+$", "", repo) # 去掉尾部所有 /
  remote_url <- paste0(repo, "/", file)
  
  ## 2. 直接 source；捕获 404 或其他错误
  ok <- tryCatch({
    source(remote_url, local = envir)
    TRUE
  }, error = function(e) {
    warning("加载 ‘", fun_name, "’ 失败，请检查链接： ‘", remote_url, "’ ", call. = FALSE)
    FALSE
  })

  ## 保留返回状态
  invisible(ok)
}